package com.xinjian.jianba.service.impl;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xinjian.jianba.dao.dwmid.MomlikeDao;
import com.xinjian.jianba.dto.MomLikeDto;
import com.xinjian.jianba.enity.MomLikeEntity;
import com.xinjian.jianba.service.MomLikeService;
import com.xinjian.jianba.utils.Utils;
@Service
public class MomLikeServiceImpl implements MomLikeService {

	@Autowired 
	private MomlikeDao momlikeDao;
	

	
	@Override
	public Long insertMomLikebyMonId(MomLikeDto momLikeDto) {
		java.util.Date date = new java.util.Date();
		Timestamp timestamp = new Timestamp(date.getTime());
		MomLikeEntity momLikeEntity=new MomLikeEntity();
		momLikeEntity.setMonId(Long.parseLong(momLikeDto.getMonId()));
		momLikeEntity.setUserId(Long.parseLong(momLikeDto.getUserId()));
		if(momLikeDto.getPubUserId().equals(momLikeDto.getUserId())){
			momLikeEntity.setStatus(1l);
		}else{
			momLikeEntity.setStatus(0l);
		}
		momLikeEntity.setPubUserId(Long.parseLong(momLikeDto.getPubUserId()));
		momLikeEntity.setAddTime(timestamp);
		momLikeEntity.setTimeAdd(new java.sql.Date(date.getTime()));
		try{
		momlikeDao.insert(momLikeEntity);
		}catch(DuplicateKeyException e){
			return -1l;
		}
		return momLikeEntity.getLikeId();
	}

	@Override
	public Long cancleLike(MomLikeDto momLikeDto) {
		Map<String,Long> map=new HashMap<String,Long>();
		map.put("userId", Long.parseLong(momLikeDto.getUserId()));
		map.put("monId", Long.parseLong(momLikeDto.getMonId()));
		long re=momlikeDao.cancleLike(map);
		return re;
	}
	

}
